package com.ruoyi.project.goods.order.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.goods.order.domain.GoodsOrderHead;
import com.ruoyi.project.goods.order.service.IGoodsOrderHeadService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 订单明细Controller
 * 
 * @author lonsn
 * @date 2020-11-12
 */
@Controller
@RequestMapping("/goods/orderHead")
public class GoodsOrderHeadController extends BaseController
{
    private String prefix = "goods/orderHead";

    @Autowired
    private IGoodsOrderHeadService goodsOrderHeadService;

    @RequiresPermissions("goods:orderHead:view")
    @GetMapping()
    public String orderHead()
    {
        return prefix + "/orderHead";
    }

    /**
     * 查询订单明细列表
     */
    @RequiresPermissions("goods:orderHead:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(GoodsOrderHead goodsOrderHead)
    {
        startPage();
        List<GoodsOrderHead> list = goodsOrderHeadService.selectGoodsOrderHeadList(goodsOrderHead);
        return getDataTable(list);
    }

    /**
     * 导出订单明细列表
     */
    @RequiresPermissions("goods:orderHead:export")
    @Log(title = "订单明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(GoodsOrderHead goodsOrderHead)
    {
        List<GoodsOrderHead> list = goodsOrderHeadService.selectGoodsOrderHeadList(goodsOrderHead);
        ExcelUtil<GoodsOrderHead> util = new ExcelUtil<GoodsOrderHead>(GoodsOrderHead.class);
        return util.exportExcel(list, "orderHead");
    }

    /**
     * 新增订单明细
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存订单明细
     */
    @RequiresPermissions("goods:orderHead:add")
    @Log(title = "订单明细", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(GoodsOrderHead goodsOrderHead)
    {
        return toAjax(goodsOrderHeadService.insertGoodsOrderHead(goodsOrderHead));
    }

    /**
     * 修改订单明细
     */
    @GetMapping("/edit/{orderHeadId}")
    public String edit(@PathVariable("orderHeadId") Long orderHeadId, ModelMap mmap)
    {
        GoodsOrderHead goodsOrderHead = goodsOrderHeadService.selectGoodsOrderHeadById(orderHeadId);
        mmap.put("goodsOrderHead", goodsOrderHead);
        return prefix + "/edit";
    }

    /**
     * 修改保存订单明细
     */
    @RequiresPermissions("goods:orderHead:edit")
    @Log(title = "订单明细", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(GoodsOrderHead goodsOrderHead)
    {
        return toAjax(goodsOrderHeadService.updateGoodsOrderHead(goodsOrderHead));
    }

    /**
     * 删除订单明细
     */
    @RequiresPermissions("goods:orderHead:remove")
    @Log(title = "订单明细", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(goodsOrderHeadService.deleteGoodsOrderHeadByIds(ids));
    }
}
